<template>
    <div>
      <home-header></home-header>
      <home-swiper :List = 'swiperList'></home-swiper>
      <home-icons :List = 'iconsList'></home-icons>
      <home-recommend :List = 'recommendList'></home-recommend>
      <home-weekend :List = 'weekendList'></home-weekend>
    </div>
</template>
<script type="text/ecmascript-6">
import homeHeader from './components/Header'
import homeSwiper from './components/Swiper'
import homeIcons from './components/Icons'
import homeRecommend from './components/Recommend'
import homeWeekend from './components/Weekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default{
  name: 'Home',
  components: {
    homeHeader,
    homeSwiper,
    homeIcons,
    homeRecommend,
    homeWeekend
  },
  data () {
    return {
      langeCity: '',
      swiperList: [],
      iconsList: [],
      recommendList: [],
      weekendList: []
    }
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json?city=' + this.city)
        .then((res) => {
          res = res.data
          console.log(res)
          if (res.ret && res.data) {
            this.swiperList = res.data.swiperList
            this.iconsList = res.data.iconsList
            this.recommendList = res.data.recommendList
            this.weekendList = res.data.weekendList
          }
        })
    }
  },
  mounted () {
    this.langeCity = this.city
    this.getHomeInfo()
  },
  activated () {
    if (this.langeCity !== this.city) {
      this.langeCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>
<style>
</style>
